const db = require("../db/mysql");
const getstulist = "select * from ev_stu";
var timer;
exports.conf = function(con){
    con.on("text",function(data){
        var data = JSON.parse(data)
        console.log(data);
        if (data.type=="getlist") {
            db.query(getstulist,(err,result)=>{
                if (err) {
                    return res.cc(err)
                }
                console.log(result);
                let data = {
                    status:0,
                    message:"all data",
                    data:result
                }
                let str = JSON.stringify(data)
                // 执行成功
                con.sendText(str)
            })
                timer = setInterval(() => {
                    db.query(getstulist,(err,result)=>{
                        if (err) {
                            return res.cc(err)
                        }
                        let data = {
                            status:0,
                            message:"all data",
                            data:result
                        }
                        let str = JSON.stringify(data)
                        // 执行成功
                        con.sendText(str)
                    })
                }, 1000);
            }
            
        })
        con.on("close",function(e){
            clearInterval(timer)
            console.log("服务器连接关闭");
        })
        con.on("error",function(e){
            console.log("服务器端异常");
        })
}